var maxJumps = function(arr, d) {
    let hasJump = []
    let JumpCount = 0
    arr.forEach((item, index) => {
        hasJump[index] = 0
    });

    function jump(curIndex, count) {
        JumpCount = count > JumpCount ? count : JumpCount
        let curItem = arr[curIndex]
        let min = curIndex - d < 0 ? 0 : curIndex - d
        let max = curIndex + d > arr.length - 1 ? arr.length - 1 : curIndex + d
        let canMin = min
        let canMax = max
        for (let i = min; i <= max; i++) {
            const item = arr[i];
            if (item >= curItem && i < curIndex) {
                canMin = i + 1
            }
            if (item >= curItem && i > curIndex) {
                canMax = i - 1
                break
            }
        }
        for (let j = canMin; j <= canMax; j++) {
            const item = arr[j];
            if (j === curIndex) {
                continue
            }
            if (hasJump[j] >= count + 1) {
                continue
            }
            hasJump[j] = count + 1
            jump(j, count + 1)
        }
    }
    arr.forEach((item, index) => {
        if (hasJump[index] === 0) {
            jump(index, 0)
        }
    });
    return JumpCount + 1
};
console.log(maxJumps([6, 4, 14, 6, 8, 13, 9, 7, 10, 6, 12], 2))